--
-- PostgreSQL database dump
--

-- Started on 2012-05-07 21:09:52

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- TOC entry 8 (class 2615 OID 18898)
-- Name: forum; Type: SCHEMA; Schema: -; Owner: postgres
--

CREATE SCHEMA forum;


ALTER SCHEMA forum OWNER TO postgres;

--
-- TOC entry 7 (class 2615 OID 18625)
-- Name: monitora; Type: SCHEMA; Schema: -; Owner: apogeu
--

CREATE SCHEMA monitora;


ALTER SCHEMA monitora OWNER TO apogeu;

--
-- TOC entry 378 (class 2612 OID 16386)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres
--

CREATE PROCEDURAL LANGUAGE plpgsql;


ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO postgres;

SET search_path = forum, pg_catalog;

--
-- TOC entry 31 (class 1255 OID 18899)
-- Dependencies: 8 378
-- Name: sf_arquivo(character varying); Type: FUNCTION; Schema: forum; Owner: postgres
--

CREATE FUNCTION sf_arquivo(p_nome character varying) RETURNS bytea
    LANGUAGE plpgsql
    AS $$
	DECLARE V_ARQUIVO BYTEA;
	BEGIN
		SELECT ARQUIVO INTO V_ARQUIVO 
			FROM FORUM.TB_TEXTOS
			WHERE LOWER(NOME) LIKE LOWER(P_NOME);

		RETURN V_ARQUIVO;
	END;
	$$;


ALTER FUNCTION forum.sf_arquivo(p_nome character varying) OWNER TO postgres;

--
-- TOC entry 1570 (class 1259 OID 18900)
-- Dependencies: 8
-- Name: sq_forum; Type: SEQUENCE; Schema: forum; Owner: postgres
--

CREATE SEQUENCE sq_forum
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE forum.sq_forum OWNER TO postgres;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 1571 (class 1259 OID 18902)
-- Dependencies: 1872 8
-- Name: tb_forum; Type: TABLE; Schema: forum; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_forum (
    cd_forum integer DEFAULT nextval('sq_forum'::regclass) NOT NULL,
    titulo character varying(200),
    imagem1 bytea,
    imagem2 bytea,
    conteudo text,
    imagem3 bytea,
    imagem4 bytea
);


ALTER TABLE forum.tb_forum OWNER TO postgres;

--
-- TOC entry 32 (class 1255 OID 18909)
-- Dependencies: 378 8 342
-- Name: sf_forum_codigo(integer); Type: FUNCTION; Schema: forum; Owner: postgres
--

CREATE FUNCTION sf_forum_codigo(p_codigo integer) RETURNS SETOF tb_forum
    LANGUAGE plpgsql
    AS $$
	BEGIN
		RETURN QUERY
			SELECT * FROM FORUM.TB_FORUM F
				WHERE F.CD_FORUM = P_CODIGO;

		RETURN;
	END;
	$$;


ALTER FUNCTION forum.sf_forum_codigo(p_codigo integer) OWNER TO postgres;

--
-- TOC entry 1572 (class 1259 OID 18910)
-- Dependencies: 1677 8
-- Name: vw_forum_codigo_titulo; Type: VIEW; Schema: forum; Owner: postgres
--

CREATE VIEW vw_forum_codigo_titulo AS
    SELECT f.cd_forum, f.titulo, NULL::unknown AS conteudo, NULL::unknown AS imagem1, NULL::unknown AS imagem2, NULL::unknown AS imagem3, NULL::unknown AS imagem4 FROM tb_forum f;


ALTER TABLE forum.vw_forum_codigo_titulo OWNER TO postgres;

--
-- TOC entry 27 (class 1255 OID 18914)
-- Dependencies: 378 8 345
-- Name: sf_forum_titulos(); Type: FUNCTION; Schema: forum; Owner: postgres
--

CREATE FUNCTION sf_forum_titulos() RETURNS SETOF vw_forum_codigo_titulo
    LANGUAGE plpgsql
    AS $$
	BEGIN
		RETURN QUERY
			SELECT * FROM FORUM.VW_FORUM_CODIGO_TITULO;

		RETURN;
	END;
	$$;


ALTER FUNCTION forum.sf_forum_titulos() OWNER TO postgres;

--
-- TOC entry 28 (class 1255 OID 18915)
-- Dependencies: 8 378
-- Name: sf_login_valido(character varying, character varying); Type: FUNCTION; Schema: forum; Owner: postgres
--

CREATE FUNCTION sf_login_valido(p_usuario character varying, p_senha character varying) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	BEGIN
		IF (EXISTS (SELECT * FROM FORUM.TB_LOGIN L WHERE LOWER(L.USUARIO) LIKE LOWER(P_USUARIO) AND LOWER(L.SENHA) LIKE LOWER(P_SENHA))) THEN
			RETURN 0;
		ELSE
			RETURN 1;
		END IF;
	END;
	$$;


ALTER FUNCTION forum.sf_login_valido(p_usuario character varying, p_senha character varying) OWNER TO postgres;

--
-- TOC entry 33 (class 1255 OID 18916)
-- Dependencies: 378 8
-- Name: sf_nomes(); Type: FUNCTION; Schema: forum; Owner: postgres
--

CREATE FUNCTION sf_nomes() RETURNS SETOF character varying
    LANGUAGE plpgsql
    AS $$
	BEGIN
		RETURN QUERY SELECT NOME FROM FORUM.TB_TEXTOS;
		RETURN;
	END;
	$$;


ALTER FUNCTION forum.sf_nomes() OWNER TO postgres;

--
-- TOC entry 34 (class 1255 OID 18917)
-- Dependencies: 378 8
-- Name: sp_remove_integrantes(); Type: FUNCTION; Schema: forum; Owner: postgres
--

CREATE FUNCTION sp_remove_integrantes() RETURNS integer
    LANGUAGE plpgsql
    AS $$
	BEGIN
		DELETE FROM FORUM.TB_INTEGRANTES;
		RETURN 0;
	END;
	$$;


ALTER FUNCTION forum.sp_remove_integrantes() OWNER TO postgres;

--
-- TOC entry 35 (class 1255 OID 18918)
-- Dependencies: 378 8
-- Name: sp_remove_objetivos(); Type: FUNCTION; Schema: forum; Owner: postgres
--

CREATE FUNCTION sp_remove_objetivos() RETURNS integer
    LANGUAGE plpgsql
    AS $$
	BEGIN
		DELETE FROM FORUM.TB_OBJETIVO;
		RETURN 1;
	END;
	$$;


ALTER FUNCTION forum.sp_remove_objetivos() OWNER TO postgres;

--
-- TOC entry 36 (class 1255 OID 18919)
-- Dependencies: 378 8
-- Name: sp_remove_organizacao(); Type: FUNCTION; Schema: forum; Owner: postgres
--

CREATE FUNCTION sp_remove_organizacao() RETURNS integer
    LANGUAGE plpgsql
    AS $$
	BEGIN
		DELETE FROM FORUM.TB_ORGANIZACAO;
		RETURN 1;
	END;
	$$;


ALTER FUNCTION forum.sp_remove_organizacao() OWNER TO postgres;

SET search_path = monitora, pg_catalog;

--
-- TOC entry 24 (class 1255 OID 18659)
-- Dependencies: 7 378
-- Name: alterar_login(character varying, character varying, character varying); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION alterar_login(p_prefeitura character varying, p_cpf character varying, p_senha character varying) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	DECLARE CODIGO INT;
	BEGIN
		IF (NOT EXISTS(SELECT * FROM MONITORA.TB_PREFEITURA
				WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA))) THEN
			RETURN 1;
		END IF;

		SELECT CD_PREFEITURA INTO CODIGO 
			FROM MONITORA.TB_PREFEITURA 
			WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA);

		UPDATE MONITORA.TB_PREFEITURA 
			SET CPF = P_CPF, SENHA = P_SENHA
			WHERE CD_PREFEITURA = CODIGO;

		RETURN 0;
	END;
	$$;


ALTER FUNCTION monitora.alterar_login(p_prefeitura character varying, p_cpf character varying, p_senha character varying) OWNER TO postgres;

--
-- TOC entry 44 (class 1255 OID 19063)
-- Dependencies: 7 378
-- Name: dados_confirmacao1(character varying); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION dados_confirmacao1(p_prefeitura character varying) RETURNS character varying
    LANGUAGE plpgsql
    AS $$
	DECLARE CODIGO INT;
		DATA1 DATE;
		TEXTO VARCHAR;
	BEGIN
		IF (NOT EXISTS(SELECT * FROM MONITORA.TB_PREFEITURA WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA))) THEN
			RETURN '';
		END IF;

		SELECT CD_PREFEITURA INTO CODIGO
			FROM MONITORA.TB_PREFEITURA
			WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA);

		SELECT NOME, DATA INTO TEXTO, DATA1 FROM MONITORA.TB_CONFIRMACAO1 WHERE CD_PREFEITURA = CODIGO;

		RETURN TEXTO || ' (' || TO_CHAR(DATA1, 'DD/MM/YYYY') || ')';
	END;
	$$;


ALTER FUNCTION monitora.dados_confirmacao1(p_prefeitura character varying) OWNER TO postgres;

--
-- TOC entry 30 (class 1255 OID 18758)
-- Dependencies: 378 7
-- Name: formulario1_arquivo(integer, integer); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION formulario1_arquivo(p_prefeitura integer, p_arquivo integer) RETURNS bytea
    LANGUAGE plpgsql
    AS $$
	DECLARE ARQUIVO BYTEA;
	BEGIN
		IF (P_ARQUIVO = 1) THEN
			SELECT QA2 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 2) THEN
			SELECT QA3 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 3) THEN
			SELECT QS5 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 4) THEN
			SELECT QS6 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 5) THEN
			SELECT QS7 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 6) THEN
			SELECT QS8 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 7) THEN
			SELECT QS92 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 8) THEN
			SELECT QS112 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 9) THEN
			SELECT QS122 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 10) THEN
			SELECT QS132 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 11) THEN
			SELECT QS133 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 12) THEN
			SELECT QS142 INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		END IF;
				

		RETURN ARQUIVO;
	END;
	$$;


ALTER FUNCTION monitora.formulario1_arquivo(p_prefeitura integer, p_arquivo integer) OWNER TO postgres;

--
-- TOC entry 41 (class 1255 OID 18804)
-- Dependencies: 378 7
-- Name: formulario1_nome_arquivo(integer, integer); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION formulario1_nome_arquivo(p_prefeitura integer, p_arquivo integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $$
	DECLARE ARQUIVO VARCHAR(100);
	BEGIN
		IF (P_ARQUIVO = 1) THEN
			SELECT QA2N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 2) THEN
			SELECT QA3N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 3) THEN
			SELECT QS5N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 4) THEN
			SELECT QS6N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 5) THEN
			SELECT QS7N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 6) THEN
			SELECT QS8N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 7) THEN
			SELECT QS92N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 8) THEN
			SELECT QS112N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 9) THEN
			SELECT QS122N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 10) THEN
			SELECT QS132N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 11) THEN
			SELECT QS133N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 12) THEN
			SELECT QS142N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO1 WHERE CD_PREFEITURA = P_PREFEITURA;
		END IF;
				

		RETURN ARQUIVO;
	END;
	$$;


ALTER FUNCTION monitora.formulario1_nome_arquivo(p_prefeitura integer, p_arquivo integer) OWNER TO postgres;

--
-- TOC entry 1567 (class 1259 OID 18660)
-- Dependencies: 7
-- Name: sq_formulario1; Type: SEQUENCE; Schema: monitora; Owner: postgres
--

CREATE SEQUENCE sq_formulario1
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE monitora.sq_formulario1 OWNER TO postgres;

--
-- TOC entry 1568 (class 1259 OID 18677)
-- Dependencies: 1871 7
-- Name: tb_formulario1; Type: TABLE; Schema: monitora; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_formulario1 (
    cd_formulario1 integer DEFAULT nextval('sq_formulario1'::regclass) NOT NULL,
    cd_prefeitura integer,
    q1 character varying(10),
    qn1 character varying(200),
    q2 date,
    qa2n character varying(100),
    qa2 bytea,
    q3 date,
    qa3n character varying(100),
    qa3 bytea,
    q4 character varying(10),
    qn41 character varying(100),
    qn42 character varying(200),
    qs41 character varying(10),
    qsn4 character varying(100),
    qs42 character varying(50),
    q5 character varying(10),
    qn5 character varying(200),
    qs5n character varying(100),
    qs5 bytea,
    q6 character varying(10),
    qs6n character varying(100),
    qs6 bytea,
    q7 character varying(10),
    qs7n character varying(100),
    qs7 bytea,
    qn71 character varying(200),
    qn72 character varying(200),
    q8 character varying(10),
    qs8n character varying(100),
    qs8 bytea,
    qn8 character varying(200),
    q9 character varying(10),
    qs91 date,
    qs92n character varying(100),
    qs92 bytea,
    qn9 character varying(200),
    q10 character varying(10),
    qn10 character varying(200),
    q11 character varying(10),
    qs111 date,
    qs112n character varying(100),
    qs112 bytea,
    qn11 character varying(200),
    q12 character varying(10),
    qs121 date,
    qs122n character varying(100),
    qs122 bytea,
    qn12 character varying(200),
    q13 character varying(10),
    qs131 date,
    qs132n character varying(100),
    qs132 bytea,
    qs133n character varying(100),
    qs133 bytea,
    qn131 character varying(200),
    qn132 character varying(200),
    qn133 character varying(200),
    q14 character varying(10),
    qs141 date,
    qs142n character varying(100),
    qs142 bytea,
    qn14 character varying(200)
);


ALTER TABLE monitora.tb_formulario1 OWNER TO postgres;

--
-- TOC entry 1569 (class 1259 OID 18742)
-- Dependencies: 1676 7
-- Name: vw_formulario1_sem_arquivo; Type: VIEW; Schema: monitora; Owner: postgres
--

CREATE VIEW vw_formulario1_sem_arquivo AS
    SELECT tb_formulario1.cd_prefeitura, tb_formulario1.q1, tb_formulario1.q10, tb_formulario1.q11, tb_formulario1.q12, tb_formulario1.q13, tb_formulario1.q14, tb_formulario1.q2, tb_formulario1.q3, tb_formulario1.q4, tb_formulario1.q5, tb_formulario1.q6, tb_formulario1.q7, tb_formulario1.q8, tb_formulario1.q9, NULL::unknown AS qa2, tb_formulario1.qa2n, NULL::unknown AS qa3, tb_formulario1.qa3n, tb_formulario1.qn1, tb_formulario1.qn10, tb_formulario1.qn11, tb_formulario1.qn12, tb_formulario1.qn131, tb_formulario1.qn132, tb_formulario1.qn133, tb_formulario1.qn14, tb_formulario1.qn41, tb_formulario1.qn42, tb_formulario1.qn5, tb_formulario1.qn71, tb_formulario1.qn72, tb_formulario1.qn8, tb_formulario1.qn9, tb_formulario1.qs111, NULL::unknown AS qs112, tb_formulario1.qs112n, tb_formulario1.qs121, NULL::unknown AS qs122, tb_formulario1.qs122n, tb_formulario1.qs131, NULL::unknown AS qs132, tb_formulario1.qs132n, NULL::unknown AS qs133, tb_formulario1.qs133n, tb_formulario1.qs141, NULL::unknown AS qs142, tb_formulario1.qs142n, tb_formulario1.qs41, tb_formulario1.qs42, NULL::unknown AS qs5, tb_formulario1.qs5n, NULL::unknown AS qs6, tb_formulario1.qs6n, NULL::unknown AS qs7, tb_formulario1.qs7n, NULL::unknown AS qs8, tb_formulario1.qs8n, tb_formulario1.qs91, NULL::unknown AS qs92, tb_formulario1.qs92n, tb_formulario1.qsn4, tb_formulario1.cd_formulario1 FROM tb_formulario1;


ALTER TABLE monitora.vw_formulario1_sem_arquivo OWNER TO postgres;

--
-- TOC entry 29 (class 1255 OID 18748)
-- Dependencies: 339 7 378
-- Name: formulario1_sem_arquivo(integer); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION formulario1_sem_arquivo(p_prefeitura integer) RETURNS SETOF vw_formulario1_sem_arquivo
    LANGUAGE plpgsql
    AS $$
	BEGIN
		RETURN QUERY SELECT *
			FROM MONITORA.VW_FORMULARIO1_SEM_ARQUIVO
				WHERE CD_PREFEITURA = P_PREFEITURA;

		RETURN;
	END;
	$$;


ALTER FUNCTION monitora.formulario1_sem_arquivo(p_prefeitura integer) OWNER TO postgres;

--
-- TOC entry 40 (class 1255 OID 19109)
-- Dependencies: 7 378
-- Name: formulario2_arquivo(integer, integer); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION formulario2_arquivo(p_prefeitura integer, p_arquivo integer) RETURNS bytea
    LANGUAGE plpgsql
    AS $$
	DECLARE ARQUIVO BYTEA;
	BEGIN
		IF (P_ARQUIVO = 1) THEN
			SELECT Q2A INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO2 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 2) THEN
			SELECT Q10A INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO2 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 3) THEN
			SELECT Q11SA INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO2 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 4) THEN
			SELECT Q13A INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO2 WHERE CD_PREFEITURA = P_PREFEITURA;
		END IF;
				

		RETURN ARQUIVO;
	END;
	$$;


ALTER FUNCTION monitora.formulario2_arquivo(p_prefeitura integer, p_arquivo integer) OWNER TO postgres;

--
-- TOC entry 42 (class 1255 OID 19110)
-- Dependencies: 378 7
-- Name: formulario2_nome_arquivo(integer, integer); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION formulario2_nome_arquivo(p_prefeitura integer, p_arquivo integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $$
	DECLARE ARQUIVO VARCHAR(100);
	BEGIN
		IF (P_ARQUIVO = 1) THEN
			SELECT QA2N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO2 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 2) THEN
			SELECT QA10N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO2 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 3) THEN
			SELECT QA11SN INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO2 WHERE CD_PREFEITURA = P_PREFEITURA;
		ELSIF (P_ARQUIVO = 4) THEN
			SELECT QA13N INTO ARQUIVO 
				FROM MONITORA.TB_FORMULARIO2 WHERE CD_PREFEITURA = P_PREFEITURA;
		END IF;
				

		RETURN ARQUIVO;
	END;
	$$;


ALTER FUNCTION monitora.formulario2_nome_arquivo(p_prefeitura integer, p_arquivo integer) OWNER TO postgres;

--
-- TOC entry 1585 (class 1259 OID 19076)
-- Dependencies: 7
-- Name: sq_formulario2; Type: SEQUENCE; Schema: monitora; Owner: postgres
--

CREATE SEQUENCE sq_formulario2
    START WITH 81
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE monitora.sq_formulario2 OWNER TO postgres;

--
-- TOC entry 1588 (class 1259 OID 19136)
-- Dependencies: 1880 7
-- Name: tb_formulario2; Type: TABLE; Schema: monitora; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_formulario2 (
    cd_formulario2 integer DEFAULT nextval('sq_formulario2'::regclass) NOT NULL,
    cd_prefeitura integer,
    q1 character varying(10),
    q1n character varying(200),
    q2 character varying(10),
    qa2n character varying(100),
    q2a bytea,
    q3 character varying(10),
    q3n character varying(200),
    q4 character varying(10),
    q4n character varying(200),
    q51 character varying(20),
    q52 character varying(20),
    q53 character varying(20),
    q54 character varying(20),
    q6 character varying(10),
    q6n character varying(200),
    q6s character varying(200),
    q6t character varying(200),
    q7 character varying(10),
    q7n character varying(200),
    q8 character varying(10),
    q8n character varying(200),
    q9 character varying(10),
    q9n character varying(200),
    q10 character varying(200),
    qa10n character varying(100),
    q10a bytea,
    q11 character varying(10),
    q11n character varying(200),
    qa11sn character varying(100),
    q11sa bytea,
    q12 character varying(10),
    q12n character varying(200),
    q13 character varying(20),
    qa13n character varying(100),
    q13a bytea
);


ALTER TABLE monitora.tb_formulario2 OWNER TO postgres;

--
-- TOC entry 1589 (class 1259 OID 19150)
-- Dependencies: 1678 7
-- Name: vw_formulario2_sem_arquivo; Type: VIEW; Schema: monitora; Owner: postgres
--

CREATE VIEW vw_formulario2_sem_arquivo AS
    SELECT tb_formulario2.cd_prefeitura, tb_formulario2.cd_formulario2, tb_formulario2.q1, tb_formulario2.q1n, tb_formulario2.q2, tb_formulario2.qa2n, NULL::unknown AS q2a, tb_formulario2.q3, tb_formulario2.q3n, tb_formulario2.q4, tb_formulario2.q4n, tb_formulario2.q51, tb_formulario2.q52, tb_formulario2.q53, tb_formulario2.q54, tb_formulario2.q6, tb_formulario2.q6n, tb_formulario2.q6s, tb_formulario2.q6t, tb_formulario2.q7, tb_formulario2.q7n, tb_formulario2.q8, tb_formulario2.q8n, tb_formulario2.q9, tb_formulario2.q9n, tb_formulario2.q10, tb_formulario2.qa10n, NULL::unknown AS q10a, tb_formulario2.q11, tb_formulario2.q11n, tb_formulario2.qa11sn, NULL::unknown AS q11sa, tb_formulario2.q12, tb_formulario2.q12n, tb_formulario2.q13, tb_formulario2.qa13n, NULL::unknown AS q13a FROM tb_formulario2;


ALTER TABLE monitora.vw_formulario2_sem_arquivo OWNER TO postgres;

--
-- TOC entry 39 (class 1255 OID 19155)
-- Dependencies: 376 378 7
-- Name: formulario2_sem_arquivo(integer); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION formulario2_sem_arquivo(p_prefeitura integer) RETURNS SETOF vw_formulario2_sem_arquivo
    LANGUAGE plpgsql
    AS $$
	BEGIN
		RETURN QUERY SELECT *
			FROM MONITORA.VW_FORMULARIO2_SEM_ARQUIVO
				WHERE CD_PREFEITURA = P_PREFEITURA;

		RETURN;
	END;
	$$;


ALTER FUNCTION monitora.formulario2_sem_arquivo(p_prefeitura integer) OWNER TO postgres;

--
-- TOC entry 25 (class 1255 OID 18692)
-- Dependencies: 7 378
-- Name: get_codigo(character varying); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION get_codigo(p_prefeitura character varying) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	DECLARE CODIGO INT;
	BEGIN
		SELECT CD_PREFEITURA INTO CODIGO
			FROM MONITORA.TB_PREFEITURA
			WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA);

		RETURN CODIGO;
	END;
	$$;


ALTER FUNCTION monitora.get_codigo(p_prefeitura character varying) OWNER TO postgres;

--
-- TOC entry 37 (class 1255 OID 18657)
-- Dependencies: 7 378
-- Name: get_prefeituras(); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION get_prefeituras() RETURNS SETOF character varying
    LANGUAGE plpgsql
    AS $$
	BEGIN
		RETURN QUERY SELECT DISTINCT NOME AS NOME FROM MONITORA.TB_PREFEITURA ORDER BY NOME;
		RETURN;
	END;
	$$;


ALTER FUNCTION monitora.get_prefeituras() OWNER TO postgres;

--
-- TOC entry 46 (class 1255 OID 19027)
-- Dependencies: 378 7
-- Name: inserir_confirmacao1(character varying, date, character varying); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION inserir_confirmacao1(p_nome character varying, p_data date, p_prefeitura character varying) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	DECLARE CODIGO INT;
	
	BEGIN
		IF (NOT EXISTS(SELECT * FROM MONITORA.TB_PREFEITURA WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA))) THEN
			RETURN 1;
		END IF;

		SELECT CD_PREFEITURA INTO CODIGO 
			FROM MONITORA.TB_PREFEITURA 
			WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA);

		DELETE FROM MONITORA.TB_CONFIRMACAO1
			WHERE CD_PREFEITURA = CODIGO;

		INSERT INTO MONITORA.TB_CONFIRMACAO1 
			(NOME, DATA, CD_PREFEITURA)
			VALUES
			(P_NOME, P_DATA, CODIGO);

		RETURN 0;
	END;
	$$;


ALTER FUNCTION monitora.inserir_confirmacao1(p_nome character varying, p_data date, p_prefeitura character varying) OWNER TO postgres;

--
-- TOC entry 47 (class 1255 OID 19112)
-- Dependencies: 378 7
-- Name: inserir_confirmacao2(character varying, date, character varying); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION inserir_confirmacao2(p_nome character varying, p_data date, p_prefeitura character varying) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	DECLARE CODIGO INT;
	
	BEGIN
		IF (NOT EXISTS(SELECT * FROM MONITORA.TB_PREFEITURA WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA))) THEN
			RETURN 1;
		END IF;

		SELECT CD_PREFEITURA INTO CODIGO 
			FROM MONITORA.TB_PREFEITURA 
			WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA);

		DELETE FROM MONITORA.TB_CONFIRMACAO2
			WHERE CD_PREFEITURA = CODIGO;

		INSERT INTO MONITORA.TB_CONFIRMACAO2 
			(NOME, DATA, CD_PREFEITURA)
			VALUES
			(P_NOME, P_DATA, CODIGO);

		RETURN 0;
	END;
	$$;


ALTER FUNCTION monitora.inserir_confirmacao2(p_nome character varying, p_data date, p_prefeitura character varying) OWNER TO postgres;

--
-- TOC entry 21 (class 1255 OID 18648)
-- Dependencies: 7 378
-- Name: login_valido(character varying, character varying); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION login_valido(p_nome character varying, p_senha character varying) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	BEGIN
		IF (EXISTS (SELECT * FROM MONITORA.TB_PREFEITURA 
				WHERE LOWER(NOME) LIKE LOWER(P_NOME) AND LOWER(SENHA) LIKE LOWER(P_SENHA))) THEN
			RETURN 0;
		END IF;

		RETURN 1;
	END;
	$$;


ALTER FUNCTION monitora.login_valido(p_nome character varying, p_senha character varying) OWNER TO postgres;

--
-- TOC entry 43 (class 1255 OID 19029)
-- Dependencies: 7 378
-- Name: prefeitura_confirmacao1(character varying); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION prefeitura_confirmacao1(p_prefeitura character varying) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	DECLARE CODIGO INT;
	BEGIN
		IF (NOT EXISTS(SELECT * FROM MONITORA.TB_PREFEITURA WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA))) THEN
			RETURN 1;
		END IF;

		SELECT CD_PREFEITURA INTO CODIGO
			FROM MONITORA.TB_PREFEITURA
			WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA);

		IF (EXISTS (SELECT * FROM MONITORA.TB_CONFIRMACAO1 WHERE CD_PREFEITURA = CODIGO)) THEN
			RETURN 0;
		END IF;

		RETURN 1;
	END;
	$$;


ALTER FUNCTION monitora.prefeitura_confirmacao1(p_prefeitura character varying) OWNER TO postgres;

--
-- TOC entry 45 (class 1255 OID 19064)
-- Dependencies: 7 378
-- Name: prefeitura_confirmacao1(); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION prefeitura_confirmacao1() RETURNS SETOF character varying
    LANGUAGE plpgsql
    AS $$
	DECLARE REGISTRO RECORD;
		REGISTRO2 RECORD;
		TEXTO VARCHAR;
	BEGIN
		FOR REGISTRO IN (SELECT * FROM MONITORA.TB_PREFEITURA ORDER BY NOME) LOOP
			TEXTO := REGISTRO.NOME;

			FOR REGISTRO2 IN (SELECT * FROM MONITORA.TB_CONFIRMACAO1 WHERE CD_PREFEITURA = REGISTRO.CD_PREFEITURA) LOOP
				TEXTO := TEXTO || ' - (Finalizado ' || TO_CHAR(REGISTRO2.DATA, 'DD/MM/YYYY') || ')';
			END LOOP;

			--RAISE NOTICE 'RESULTADO %', TEXTO;

			RETURN NEXT TEXTO;
		END LOOP;

		RETURN;
	END;
	$$;


ALTER FUNCTION monitora.prefeitura_confirmacao1() OWNER TO postgres;

--
-- TOC entry 22 (class 1255 OID 19113)
-- Dependencies: 378 7
-- Name: prefeitura_confirmacao2(character varying); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION prefeitura_confirmacao2(p_prefeitura character varying) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	DECLARE CODIGO INT;
	BEGIN
		IF (NOT EXISTS(SELECT * FROM MONITORA.TB_PREFEITURA WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA))) THEN
			RETURN 1;
		END IF;

		SELECT CD_PREFEITURA INTO CODIGO
			FROM MONITORA.TB_PREFEITURA
			WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA);

		IF (EXISTS (SELECT * FROM MONITORA.TB_CONFIRMACAO2 WHERE CD_PREFEITURA = CODIGO)) THEN
			RETURN 0;
		END IF;

		RETURN 1;
	END;
	$$;


ALTER FUNCTION monitora.prefeitura_confirmacao2(p_prefeitura character varying) OWNER TO postgres;

--
-- TOC entry 48 (class 1255 OID 19114)
-- Dependencies: 7 378
-- Name: prefeitura_confirmacao2(); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION prefeitura_confirmacao2() RETURNS SETOF character varying
    LANGUAGE plpgsql
    AS $$
	DECLARE REGISTRO RECORD;
		REGISTRO2 RECORD;
		TEXTO VARCHAR;
	BEGIN
		FOR REGISTRO IN (SELECT * FROM MONITORA.TB_PREFEITURA ORDER BY NOME) LOOP
			TEXTO := REGISTRO.NOME;

			FOR REGISTRO2 IN (SELECT * FROM MONITORA.TB_CONFIRMACAO2 WHERE CD_PREFEITURA = REGISTRO.CD_PREFEITURA) LOOP
				TEXTO := TEXTO || ' - (Finalizado ' || TO_CHAR(REGISTRO2.DATA, 'DD/MM/YYYY') || ')';
			END LOOP;

			--RAISE NOTICE 'RESULTADO %', TEXTO;

			RETURN NEXT TEXTO;
		END LOOP;

		RETURN;
	END;
	$$;


ALTER FUNCTION monitora.prefeitura_confirmacao2() OWNER TO postgres;

--
-- TOC entry 23 (class 1255 OID 18658)
-- Dependencies: 7 378
-- Name: valida_login(character varying, character varying, character varying); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION valida_login(p_prefeitura character varying, p_cpf character varying, p_senha character varying) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	BEGIN
		IF (EXISTS (SELECT * FROM MONITORA.TB_PREFEITURA
				WHERE LOWER(NOME) LIKE LOWER(P_PREFEITURA) AND
				      LOWER(CPF) LIKE LOWER(P_CPF) AND
				      LOWER(SENHA) LIKE LOWER(P_SENHA))) THEN
			RETURN 0;
		END IF;

		RETURN 1;
	END;
	$$;


ALTER FUNCTION monitora.valida_login(p_prefeitura character varying, p_cpf character varying, p_senha character varying) OWNER TO postgres;

--
-- TOC entry 26 (class 1255 OID 18691)
-- Dependencies: 7 378
-- Name: verifica_formulario1(integer); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION verifica_formulario1(p_prefeitura integer) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	BEGIN
		IF (EXISTS (SELECT * FROM MONITORA.TB_FORMULARIO1
				WHERE CD_PREFEITURA = P_PREFEITURA)) THEN
				
			DELETE FROM MONITORA.TB_FORMULARIO1
				WHERE CD_PREFEITURA = P_PREFEITURA;
			RETURN 0;
		END IF;
		
		RETURN 1;
	END;
	$$;


ALTER FUNCTION monitora.verifica_formulario1(p_prefeitura integer) OWNER TO postgres;

--
-- TOC entry 38 (class 1255 OID 19115)
-- Dependencies: 378 7
-- Name: verifica_formulario2(integer); Type: FUNCTION; Schema: monitora; Owner: postgres
--

CREATE FUNCTION verifica_formulario2(p_prefeitura integer) RETURNS integer
    LANGUAGE plpgsql
    AS $$
	BEGIN
		IF (EXISTS (SELECT * FROM MONITORA.TB_FORMULARIO2
				WHERE CD_PREFEITURA = P_PREFEITURA)) THEN
				
			DELETE FROM MONITORA.TB_FORMULARIO2
				WHERE CD_PREFEITURA = P_PREFEITURA;
			RETURN 0;
		END IF;
		
		RETURN 1;
	END;
	$$;


ALTER FUNCTION monitora.verifica_formulario2(p_prefeitura integer) OWNER TO postgres;

SET search_path = forum, pg_catalog;

--
-- TOC entry 1573 (class 1259 OID 18920)
-- Dependencies: 8
-- Name: sq_integrantes; Type: SEQUENCE; Schema: forum; Owner: postgres
--

CREATE SEQUENCE sq_integrantes
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE forum.sq_integrantes OWNER TO postgres;

--
-- TOC entry 1574 (class 1259 OID 18922)
-- Dependencies: 8
-- Name: sq_login; Type: SEQUENCE; Schema: forum; Owner: postgres
--

CREATE SEQUENCE sq_login
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE forum.sq_login OWNER TO postgres;

--
-- TOC entry 1575 (class 1259 OID 18924)
-- Dependencies: 8
-- Name: sq_objetivo; Type: SEQUENCE; Schema: forum; Owner: postgres
--

CREATE SEQUENCE sq_objetivo
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE forum.sq_objetivo OWNER TO postgres;

--
-- TOC entry 1576 (class 1259 OID 18926)
-- Dependencies: 8
-- Name: sq_organizacao; Type: SEQUENCE; Schema: forum; Owner: postgres
--

CREATE SEQUENCE sq_organizacao
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE forum.sq_organizacao OWNER TO postgres;

--
-- TOC entry 1577 (class 1259 OID 18928)
-- Dependencies: 8
-- Name: sq_textos; Type: SEQUENCE; Schema: forum; Owner: postgres
--

CREATE SEQUENCE sq_textos
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE forum.sq_textos OWNER TO postgres;

--
-- TOC entry 1578 (class 1259 OID 18930)
-- Dependencies: 1873 8
-- Name: tb_integrantes; Type: TABLE; Schema: forum; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_integrantes (
    cd_integrantes integer DEFAULT nextval('sq_integrantes'::regclass) NOT NULL,
    conteudo text
);


ALTER TABLE forum.tb_integrantes OWNER TO postgres;

--
-- TOC entry 1579 (class 1259 OID 18937)
-- Dependencies: 1874 8
-- Name: tb_login; Type: TABLE; Schema: forum; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_login (
    cd_login integer DEFAULT nextval('sq_login'::regclass) NOT NULL,
    usuario character varying(50),
    senha character varying(50)
);


ALTER TABLE forum.tb_login OWNER TO postgres;

--
-- TOC entry 1580 (class 1259 OID 18941)
-- Dependencies: 1875 8
-- Name: tb_objetivo; Type: TABLE; Schema: forum; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_objetivo (
    cd_objetivo integer DEFAULT nextval('sq_objetivo'::regclass) NOT NULL,
    conteudo text
);


ALTER TABLE forum.tb_objetivo OWNER TO postgres;

--
-- TOC entry 1581 (class 1259 OID 18948)
-- Dependencies: 1876 8
-- Name: tb_organizacao; Type: TABLE; Schema: forum; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_organizacao (
    cd_organizacao integer DEFAULT nextval('sq_organizacao'::regclass) NOT NULL,
    conteudo text
);


ALTER TABLE forum.tb_organizacao OWNER TO postgres;

--
-- TOC entry 1582 (class 1259 OID 18955)
-- Dependencies: 1877 8
-- Name: tb_textos; Type: TABLE; Schema: forum; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_textos (
    cd_textos integer DEFAULT nextval('sq_textos'::regclass) NOT NULL,
    nome character varying(100),
    arquivo bytea
);


ALTER TABLE forum.tb_textos OWNER TO postgres;

SET search_path = monitora, pg_catalog;

--
-- TOC entry 1583 (class 1259 OID 19013)
-- Dependencies: 7
-- Name: sq_confirmacao1; Type: SEQUENCE; Schema: monitora; Owner: postgres
--

CREATE SEQUENCE sq_confirmacao1
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE monitora.sq_confirmacao1 OWNER TO postgres;

--
-- TOC entry 1586 (class 1259 OID 19078)
-- Dependencies: 7
-- Name: sq_confirmacao2; Type: SEQUENCE; Schema: monitora; Owner: postgres
--

CREATE SEQUENCE sq_confirmacao2
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE monitora.sq_confirmacao2 OWNER TO postgres;

--
-- TOC entry 1565 (class 1259 OID 18649)
-- Dependencies: 7
-- Name: sq_prefeitura; Type: SEQUENCE; Schema: monitora; Owner: postgres
--

CREATE SEQUENCE sq_prefeitura
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE monitora.sq_prefeitura OWNER TO postgres;

--
-- TOC entry 1584 (class 1259 OID 19015)
-- Dependencies: 1878 7
-- Name: tb_confirmacao1; Type: TABLE; Schema: monitora; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_confirmacao1 (
    cd_confirmacao1 integer DEFAULT nextval('sq_confirmacao1'::regclass) NOT NULL,
    nome character varying(60),
    data date,
    cd_prefeitura integer
);


ALTER TABLE monitora.tb_confirmacao1 OWNER TO postgres;

--
-- TOC entry 1587 (class 1259 OID 19094)
-- Dependencies: 1879 7
-- Name: tb_confirmacao2; Type: TABLE; Schema: monitora; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_confirmacao2 (
    cd_confirmacao2 integer DEFAULT nextval('sq_confirmacao2'::regclass) NOT NULL,
    nome character varying(60),
    data date,
    cd_prefeitura integer
);


ALTER TABLE monitora.tb_confirmacao2 OWNER TO postgres;

--
-- TOC entry 1566 (class 1259 OID 18651)
-- Dependencies: 1870 7
-- Name: tb_prefeitura; Type: TABLE; Schema: monitora; Owner: postgres; Tablespace: 
--

CREATE TABLE tb_prefeitura (
    cd_prefeitura integer DEFAULT nextval('sq_prefeitura'::regclass) NOT NULL,
    nome character varying(50),
    cpf character varying(20),
    senha character varying(20)
);


ALTER TABLE monitora.tb_prefeitura OWNER TO postgres;

SET search_path = forum, pg_catalog;

--
-- TOC entry 1886 (class 2606 OID 18966)
-- Dependencies: 1571 1571
-- Name: tb_forum_pkey; Type: CONSTRAINT; Schema: forum; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_forum
    ADD CONSTRAINT tb_forum_pkey PRIMARY KEY (cd_forum);


--
-- TOC entry 1888 (class 2606 OID 18968)
-- Dependencies: 1578 1578
-- Name: tb_integrantes_pkey; Type: CONSTRAINT; Schema: forum; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_integrantes
    ADD CONSTRAINT tb_integrantes_pkey PRIMARY KEY (cd_integrantes);


--
-- TOC entry 1890 (class 2606 OID 18970)
-- Dependencies: 1579 1579
-- Name: tb_login_pkey; Type: CONSTRAINT; Schema: forum; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_login
    ADD CONSTRAINT tb_login_pkey PRIMARY KEY (cd_login);


--
-- TOC entry 1892 (class 2606 OID 18972)
-- Dependencies: 1580 1580
-- Name: tb_objetivo_pkey; Type: CONSTRAINT; Schema: forum; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_objetivo
    ADD CONSTRAINT tb_objetivo_pkey PRIMARY KEY (cd_objetivo);


--
-- TOC entry 1894 (class 2606 OID 18974)
-- Dependencies: 1581 1581
-- Name: tb_organizacao_pkey; Type: CONSTRAINT; Schema: forum; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_organizacao
    ADD CONSTRAINT tb_organizacao_pkey PRIMARY KEY (cd_organizacao);


--
-- TOC entry 1896 (class 2606 OID 18976)
-- Dependencies: 1582 1582
-- Name: tb_textos_pkey; Type: CONSTRAINT; Schema: forum; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_textos
    ADD CONSTRAINT tb_textos_pkey PRIMARY KEY (cd_textos);


SET search_path = monitora, pg_catalog;

--
-- TOC entry 1898 (class 2606 OID 19020)
-- Dependencies: 1584 1584
-- Name: tb_confirmacao1_pkey; Type: CONSTRAINT; Schema: monitora; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_confirmacao1
    ADD CONSTRAINT tb_confirmacao1_pkey PRIMARY KEY (cd_confirmacao1);


--
-- TOC entry 1900 (class 2606 OID 19099)
-- Dependencies: 1587 1587
-- Name: tb_confirmacao2_pkey; Type: CONSTRAINT; Schema: monitora; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_confirmacao2
    ADD CONSTRAINT tb_confirmacao2_pkey PRIMARY KEY (cd_confirmacao2);


--
-- TOC entry 1884 (class 2606 OID 18685)
-- Dependencies: 1568 1568
-- Name: tb_formulario1_pkey; Type: CONSTRAINT; Schema: monitora; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_formulario1
    ADD CONSTRAINT tb_formulario1_pkey PRIMARY KEY (cd_formulario1);


--
-- TOC entry 1902 (class 2606 OID 19144)
-- Dependencies: 1588 1588
-- Name: tb_formulario2_pkey; Type: CONSTRAINT; Schema: monitora; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_formulario2
    ADD CONSTRAINT tb_formulario2_pkey PRIMARY KEY (cd_formulario2);


--
-- TOC entry 1882 (class 2606 OID 18656)
-- Dependencies: 1566 1566
-- Name: tb_prefeitura_pkey; Type: CONSTRAINT; Schema: monitora; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tb_prefeitura
    ADD CONSTRAINT tb_prefeitura_pkey PRIMARY KEY (cd_prefeitura);


--
-- TOC entry 1903 (class 2606 OID 18686)
-- Dependencies: 1568 1881 1566
-- Name: fk_cd_prefeitura; Type: FK CONSTRAINT; Schema: monitora; Owner: postgres
--

ALTER TABLE ONLY tb_formulario1
    ADD CONSTRAINT fk_cd_prefeitura FOREIGN KEY (cd_prefeitura) REFERENCES tb_prefeitura(cd_prefeitura);


--
-- TOC entry 1906 (class 2606 OID 19145)
-- Dependencies: 1881 1566 1588
-- Name: fk_cd_prefeitura; Type: FK CONSTRAINT; Schema: monitora; Owner: postgres
--

ALTER TABLE ONLY tb_formulario2
    ADD CONSTRAINT fk_cd_prefeitura FOREIGN KEY (cd_prefeitura) REFERENCES tb_prefeitura(cd_prefeitura);


--
-- TOC entry 1904 (class 2606 OID 19021)
-- Dependencies: 1584 1881 1566
-- Name: fk_tb_confirmacao1_cd_prefeitura; Type: FK CONSTRAINT; Schema: monitora; Owner: postgres
--

ALTER TABLE ONLY tb_confirmacao1
    ADD CONSTRAINT fk_tb_confirmacao1_cd_prefeitura FOREIGN KEY (cd_prefeitura) REFERENCES tb_prefeitura(cd_prefeitura);


--
-- TOC entry 1905 (class 2606 OID 19100)
-- Dependencies: 1587 1881 1566
-- Name: fk_tb_confirmacao2_cd_prefeitura; Type: FK CONSTRAINT; Schema: monitora; Owner: postgres
--

ALTER TABLE ONLY tb_confirmacao2
    ADD CONSTRAINT fk_tb_confirmacao2_cd_prefeitura FOREIGN KEY (cd_prefeitura) REFERENCES tb_prefeitura(cd_prefeitura);


--
-- TOC entry 1911 (class 0 OID 0)
-- Dependencies: 3
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


-- Completed on 2012-05-07 21:09:53

--
-- PostgreSQL database dump complete
--

